﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QuanLyBanHang.DAL;
using QuanLyBanHang_NewApp.Entity;
using QuanLyBanHang_NewApp.DAL;

namespace QuanLyBanHang_NewApp.BUS
{
    public class NhaCungCapBUS
    {
        NhaCungCapDAL nccDal;

        public NhaCungCapBUS()
        {
            nccDal = new NhaCungCapDAL();
        }

        public bool themNCC(NhaCungCap ncc)
        {
            string ten = ncc.getAttribute(1);
            string dc = ncc.getAttribute(2);
            string dt = ncc.getAttribute(3);

            return nccDal.insertNCC(ten, dc, dt);
        }

        public DataTable getAllNCC()
        {
            return nccDal.selectNCC("");
        }

        public bool suaNCC(NhaCungCap ncc)
        {
            string ten = ncc.getAttribute(1);
            string dc = ncc.getAttribute(2);
            string dt = ncc.getAttribute(3);

            long mancc = long.Parse(ncc.getAttribute(0));

            return nccDal.updateNCC(mancc, ten, dc, dt);
        }

        public bool xoaNCC(long id)
        {
            return nccDal.deleteNCC(id);
        }

        public DataTable getByName(string name)
        {
            return nccDal.selectNCC(name);
        }

        public NhaCungCap timTheoID(long mancc)
        {
            DataTable dt;
            dt = nccDal.selectByID(mancc);
            if (dt.Rows.Count == 0) return null;
            DataRow row = dt.Rows[0];
            long ma = long.Parse(row["MaNCC"].ToString());
            string ten = row["TenNCC"].ToString();
            string dc = row["DiaChi"].ToString();
            string sodt = row["SoDT"].ToString();

            NhaCungCap ncc = new NhaCungCap(ma, ten, dc, sodt);
            return ncc;
        }

    }
}
